<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="../../imgs/apple_logo.ico" />
    <!-- 1. 引入bootstrap.css -->
    <link rel="stylesheet" href="../../plugins/plugins/bootstrap-3.4.1-dist/css/bootstrap.css">
    <script src="https://cdn.bootcdn.net/ajax/libs/echarts/5.1.2/echarts.js"></script>
    <title>Apple（中国）-山寨网站</title>
    <style>
        #login_div {
            /* border:1px solid red; */
            margin-top: 80px;
            padding: 30px;
            box-shadow: 2px -2px 6px #ccc;
            border-radius: 10px;
        }

        #user_enter {
            color: white;
            text-shadow: 2px 2px 4px #000;
        }
    </style>
</head>

<body>
<!-- 导航begin -->
<div class="container-fluid">
    <!-- 定义一行 -->
    <div class="row">
        <nav class="navbar navbar-inverse" role="navigation">
            <div class="container-fluid">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse"
                        data-target="#example-navbar-collapse">
                        <span class="sr-only">切换导航</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#">苹果商城</a>
                </div>
                <div  class="collapse navbar-collapse " id="example-navbar-collapse" >
                    <ul class="nav navbar-nav navbar-right">
                        <li class="active"><a href="../RH/login.html">登录</a></li>
                        <li ><a href="#">首页</a>
                        </li>
                        <li><a href="#">购物车</a></li>
                       
                        <li><a href="#">安全退出</a></li>
                        <li>
                            <p  style="display: table-cell; vertical-align: middle; "><a href="#"><img
                                        src="../../imgs/未登录.gif" style="width: 50px;height: 50px;border-radius: 50%;"
                                        class="img-responsive" alt=""></a>
                            </p>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
    </div>
</div>
<!-- 导航end -->

    <!-- 登录begin -->
    <div class="container">
        <div class="row" id="login_div">
            <form class="form-horizontal" role="form">
                <fieldset>
                    <legend>
                        <h3 id="user_enter">用户登录入口</h3>
                    </legend>
                    <div class="form-group has-feedback">
                        <label for="firstname" class="col-sm-2 control-label">用户名</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="username" placeholder="请输入用户名">
                            <span class="form-control-feedback glyphicon glyphicon-user"></span>
                        </div>
                    </div>
                    <div class="form-group has-feedback">
                        <label for="lastname" class="col-sm-2 control-label">密码</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="password" placeholder="请输入密码">
                            <span class="form-control-feedback glyphicon glyphicon-lock"></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" id="me">请记住我
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button type="button" onclick="login()" class="btn btn-default">登录</button>
                        </div>
                    </div>
                </fieldset>
            </form>
        </div>
    </div>

    <!-- 登录end -->


    <!-- 必须先引入jquery.min.js -->
    <script src="../../plugins/plugins/jquery.min.js"></script>
    <!-- 引入bootstrap.js -->
    <script src="../../plugins/plugins/bootstrap-3.4.1-dist/js/bootstrap.js"></script>

    <script>
        $(function () {
            //当dom加载完毕之后,会自动执行此处的js代码.
            //从本地存储中获取username和pwd的值
            let uname = localStorage.getItem("username");
            let pwd = localStorage.getItem("pwd");

            //js写法
            document.getElementById("username").value = uname;
            //jquery写法
            $("#password").val(pwd);
        })

        function login() {
            //1. 判断记住密码是否选中
            let ck = document.getElementById("me");
            let username = document.getElementById("username").value;
            //jquery获取的方式
            let pwd = $("#password").val();
            if (ck.checked) {
                //h5里面的本地存储 - key和value的方式 - 都是一个字符串.
                localStorage.setItem("username", username);
                localStorage.setItem("pwd", pwd);
            } else {
                //清空本地缓存
                //localStorage.clear();
                localStorage.removeItem("username");
                localStorage.removeItem("pwd");
            }

            if (username == "admin" && pwd == "123") {
                //TODO... 
                localStorage.setItem('carts', '{"admin":[]}');
                //跳转...
                window.location = "../LJL/index.html";
            }
        }
    </script>
</body>

</html>